//导入nprogress加载进度条
import axios from "axios";
// <<<<<<< HEAD
// <<<<<<< HEAD
// =======
// >>>>>>> df1777d3b16635dc1240e1251adf0ab8aa3b09d6
import "nprogress/nprogress.css";
// <<<<<<< HEAD
// <<<<<<< HEAD
// =======
// =======
import "nprogress/nprogress.css"
// >>>>>>> 69dd64d6e151c4fd72f028cbf31eb3c74ec55316

//解决跨域问题并且传入cookie
axios.defaults.withCredentials = true;

//请求的方法

//初始化一个axios对象
var instance = axios.create({
  //接口地址根路径
  baseURL: "http://localhost:3000",
  //超时时间
  timeout: 3000,
});

// 添加请求拦截器
// <<<<<<< HEAD
// <<<<<<< HEAD
// =======
// >>>>>>> df1777d3b16635dc1240e1251adf0ab8aa3b09d6
instance.interceptors.request.use(
  function (config) {
    // <<<<<<< HEAD
    // <<<<<<< HEAD
    return config;
  },
  function (error) {
    return Promise.reject(error);
    // =======
    // =======
    // >>>>>>> caf507c8e042e8c47895a584576b560ca3fd69ff
  },
  (err) => {
    return Promise.reject(err);
    // <<<<<<< HEAD
    // >>>>>>> c6600150157b18b10afb7c56f6f1b8a93bcce321
    // =======
    // >>>>>>> caf507c8e042e8c47895a584576b560ca3fd69ff
  }
);
// <<<<<<< HEAD
// =======
instance.interceptors.request.use(function (config) {


  return config;
}, function (error) {

  return Promise.reject(error);

}, err => {

  return Promise.reject(err);

});
// >>>>>>> 69dd64d6e151c4fd72f028cbf31eb3c74ec55316
// =======
// >>>>>>> df1777d3b16635dc1240e1251adf0ab8aa3b09d6

// 添加响应拦截器
instance.interceptors.response.use(
  function (response) {
    return response;
  },
  function (error) {
    return Promise.reject(error);
  }
);

export function get(url, params) {
  return new Promise((resolve, reject) => {
    instance
      .get(url, {
        params: params,
      })
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err.data);
      });
  });
}

export function post(url, params) {
  return new Promise((resolve, reject) => {
    instance
      .post(url, params)
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err.data);
      });
  });
}